﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMIS.Enums;
using SMIS.Entities;
using DX.CRC.Common.WebUtil;
using SMIS.Dals;

namespace SMIS
{
    public partial class FormAddStaff : Form
    {
        public FormAddStaff()
        {
            InitializeComponent();
        }

        private void FormAddStaff_Load(object sender, EventArgs e)
        {
            //性别
            cboSex.Items.Add(Sex.Male);
            cboSex.Items.Add(Sex.Female);
            //cboSex.SelectedIndex = 0;

            //学历
            cboEduBgd.Items.Add(EducationBgd.Bachlor);
            cboEduBgd.Items.Add(EducationBgd.Master);
            cboEduBgd.Items.Add(EducationBgd.Doctor);
            //cboEduBgd.SelectedIndex = 0;

            //工种
            CommonUtil.BindData4ComboBox(cboJob, Dal4Staff.GetJobs(), "JobName", "JobID");
            //DataTable dtJobs = Dal4Staff.GetJobs();
            //cboJob.DataSource = dtJobs;
            //cboJob.DisplayMember = "JobName";

            //部门
            CommonUtil.BindData4ComboBox(cboDepart, Dal4Staff.GetDeparts(), "DName", "DID");
            //DataTable dtDepart = Dal4Staff.GetDeparts();
            //cboDepart.DataSource = dtDepart;
            //cboDepart.DisplayMember = "DName";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Staff staff = new Staff();

            staff.SName = txtName.Text;
            //staff.Sex = CommonUtility.Convert2Enum(cboSex.SelectedText, Sex.Unknown);
            staff.Sex_Field = cboSex.SelectedItem.ToString();
            staff.Place = txtPlace.Text;
            staff.Birthday = dateTimePicker1.Value;
            //staff.EducationBackground = CommonUtility.Convert2Enum(cboEduBgd.SelectedText, EducationBgd.Unknown);
            staff.EducationBackground_Field = cboEduBgd.SelectedItem.ToString();
            staff.Major = txtMajor.Text;
            staff.StartWorkingDate = dateTimePicker2.Value;
            staff.DatesEmployed = dateTimePicker3.Value;
            staff.JobName = cboJob.Text;
            staff.DepName = cboDepart.Text;
            staff.Position = txtPosition.Text;
            staff.Remark = txtRemark.Text;

            Dal4Staff.InsertStaff(staff);
            MessageBox.Show("恭喜您添加员工信息成功！");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
